/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package sysmodel.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EcoreUtil;

import sysmodel.Association;
import sysmodel.AssociationEnd;
import sysmodel.Entity;
import sysmodel.Multiplicity;
import sysmodel.SysmodelPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Association End</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link sysmodel.impl.AssociationEndImpl#getAssociatedEntity <em>Associated Entity</em>}</li>
 *   <li>{@link sysmodel.impl.AssociationEndImpl#getAssociation <em>Association</em>}</li>
 *   <li>{@link sysmodel.impl.AssociationEndImpl#getMultiplicity <em>Multiplicity</em>}</li>
 *   <li>{@link sysmodel.impl.AssociationEndImpl#isIsNavigable <em>Is Navigable</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class AssociationEndImpl extends NamedElementImpl implements AssociationEnd {
	/**
	 * The cached value of the '{@link #getAssociatedEntity() <em>Associated Entity</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAssociatedEntity()
	 * @generated
	 * @ordered
	 */
	protected Entity associatedEntity;

	/**
	 * The default value of the '{@link #getMultiplicity() <em>Multiplicity</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMultiplicity()
	 * @generated
	 * @ordered
	 */
	protected static final Multiplicity MULTIPLICITY_EDEFAULT = Multiplicity.ZERO_OR_ONE;

	/**
	 * The cached value of the '{@link #getMultiplicity() <em>Multiplicity</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMultiplicity()
	 * @generated
	 * @ordered
	 */
	protected Multiplicity multiplicity = MULTIPLICITY_EDEFAULT;

	/**
	 * The default value of the '{@link #isIsNavigable() <em>Is Navigable</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isIsNavigable()
	 * @generated
	 * @ordered
	 */
	protected static final boolean IS_NAVIGABLE_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isIsNavigable() <em>Is Navigable</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isIsNavigable()
	 * @generated
	 * @ordered
	 */
	protected boolean isNavigable = IS_NAVIGABLE_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected AssociationEndImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SysmodelPackage.Literals.ASSOCIATION_END;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Entity getAssociatedEntity() {
		if (associatedEntity != null && associatedEntity.eIsProxy()) {
			InternalEObject oldAssociatedEntity = (InternalEObject)associatedEntity;
			associatedEntity = (Entity)eResolveProxy(oldAssociatedEntity);
			if (associatedEntity != oldAssociatedEntity) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, SysmodelPackage.ASSOCIATION_END__ASSOCIATED_ENTITY, oldAssociatedEntity, associatedEntity));
			}
		}
		return associatedEntity;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Entity basicGetAssociatedEntity() {
		return associatedEntity;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetAssociatedEntity(Entity newAssociatedEntity, NotificationChain msgs) {
		Entity oldAssociatedEntity = associatedEntity;
		associatedEntity = newAssociatedEntity;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SysmodelPackage.ASSOCIATION_END__ASSOCIATED_ENTITY, oldAssociatedEntity, newAssociatedEntity);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAssociatedEntity(Entity newAssociatedEntity) {
		if (newAssociatedEntity != associatedEntity) {
			NotificationChain msgs = null;
			if (associatedEntity != null)
				msgs = ((InternalEObject)associatedEntity).eInverseRemove(this, SysmodelPackage.ENTITY__ASSOCIATION_END, Entity.class, msgs);
			if (newAssociatedEntity != null)
				msgs = ((InternalEObject)newAssociatedEntity).eInverseAdd(this, SysmodelPackage.ENTITY__ASSOCIATION_END, Entity.class, msgs);
			msgs = basicSetAssociatedEntity(newAssociatedEntity, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SysmodelPackage.ASSOCIATION_END__ASSOCIATED_ENTITY, newAssociatedEntity, newAssociatedEntity));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Association getAssociation() {
		if (eContainerFeatureID() != SysmodelPackage.ASSOCIATION_END__ASSOCIATION) return null;
		return (Association)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetAssociation(Association newAssociation, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newAssociation, SysmodelPackage.ASSOCIATION_END__ASSOCIATION, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAssociation(Association newAssociation) {
		if (newAssociation != eInternalContainer() || (eContainerFeatureID() != SysmodelPackage.ASSOCIATION_END__ASSOCIATION && newAssociation != null)) {
			if (EcoreUtil.isAncestor(this, newAssociation))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newAssociation != null)
				msgs = ((InternalEObject)newAssociation).eInverseAdd(this, SysmodelPackage.ASSOCIATION__ASSOCIATION_END, Association.class, msgs);
			msgs = basicSetAssociation(newAssociation, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SysmodelPackage.ASSOCIATION_END__ASSOCIATION, newAssociation, newAssociation));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Multiplicity getMultiplicity() {
		return multiplicity;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMultiplicity(Multiplicity newMultiplicity) {
		Multiplicity oldMultiplicity = multiplicity;
		multiplicity = newMultiplicity == null ? MULTIPLICITY_EDEFAULT : newMultiplicity;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SysmodelPackage.ASSOCIATION_END__MULTIPLICITY, oldMultiplicity, multiplicity));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isIsNavigable() {
		return isNavigable;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setIsNavigable(boolean newIsNavigable) {
		boolean oldIsNavigable = isNavigable;
		isNavigable = newIsNavigable;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SysmodelPackage.ASSOCIATION_END__IS_NAVIGABLE, oldIsNavigable, isNavigable));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SysmodelPackage.ASSOCIATION_END__ASSOCIATED_ENTITY:
				if (associatedEntity != null)
					msgs = ((InternalEObject)associatedEntity).eInverseRemove(this, SysmodelPackage.ENTITY__ASSOCIATION_END, Entity.class, msgs);
				return basicSetAssociatedEntity((Entity)otherEnd, msgs);
			case SysmodelPackage.ASSOCIATION_END__ASSOCIATION:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetAssociation((Association)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SysmodelPackage.ASSOCIATION_END__ASSOCIATED_ENTITY:
				return basicSetAssociatedEntity(null, msgs);
			case SysmodelPackage.ASSOCIATION_END__ASSOCIATION:
				return basicSetAssociation(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case SysmodelPackage.ASSOCIATION_END__ASSOCIATION:
				return eInternalContainer().eInverseRemove(this, SysmodelPackage.ASSOCIATION__ASSOCIATION_END, Association.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SysmodelPackage.ASSOCIATION_END__ASSOCIATED_ENTITY:
				if (resolve) return getAssociatedEntity();
				return basicGetAssociatedEntity();
			case SysmodelPackage.ASSOCIATION_END__ASSOCIATION:
				return getAssociation();
			case SysmodelPackage.ASSOCIATION_END__MULTIPLICITY:
				return getMultiplicity();
			case SysmodelPackage.ASSOCIATION_END__IS_NAVIGABLE:
				return isIsNavigable();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SysmodelPackage.ASSOCIATION_END__ASSOCIATED_ENTITY:
				setAssociatedEntity((Entity)newValue);
				return;
			case SysmodelPackage.ASSOCIATION_END__ASSOCIATION:
				setAssociation((Association)newValue);
				return;
			case SysmodelPackage.ASSOCIATION_END__MULTIPLICITY:
				setMultiplicity((Multiplicity)newValue);
				return;
			case SysmodelPackage.ASSOCIATION_END__IS_NAVIGABLE:
				setIsNavigable((Boolean)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SysmodelPackage.ASSOCIATION_END__ASSOCIATED_ENTITY:
				setAssociatedEntity((Entity)null);
				return;
			case SysmodelPackage.ASSOCIATION_END__ASSOCIATION:
				setAssociation((Association)null);
				return;
			case SysmodelPackage.ASSOCIATION_END__MULTIPLICITY:
				setMultiplicity(MULTIPLICITY_EDEFAULT);
				return;
			case SysmodelPackage.ASSOCIATION_END__IS_NAVIGABLE:
				setIsNavigable(IS_NAVIGABLE_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SysmodelPackage.ASSOCIATION_END__ASSOCIATED_ENTITY:
				return associatedEntity != null;
			case SysmodelPackage.ASSOCIATION_END__ASSOCIATION:
				return getAssociation() != null;
			case SysmodelPackage.ASSOCIATION_END__MULTIPLICITY:
				return multiplicity != MULTIPLICITY_EDEFAULT;
			case SysmodelPackage.ASSOCIATION_END__IS_NAVIGABLE:
				return isNavigable != IS_NAVIGABLE_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (multiplicity: ");
		result.append(multiplicity);
		result.append(", isNavigable: ");
		result.append(isNavigable);
		result.append(')');
		return result.toString();
	}

} //AssociationEndImpl
